﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Entitty;
using ClassLibrary.DAO;

public partial class Admin_ucControl_ucNoiDungTrangHome : System.Web.UI.UserControl
{
    TblNoiDungTrangHomeDAO noidungHomeDAO = new TblNoiDungTrangHomeDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadNoiDung();
            string id = Request.QueryString["id"];
            if (id == null || id == "")
            {
                panel.Visible = false;
            }
            else
            {
                panel.Visible = true;
                LoadDetail();
            }
        }
    }
    public void LoadNoiDung()
    {
        GridView1.DataSource = noidungHomeDAO.GetNoiDung();
        GridView1.DataBind();
    }

    public void LoadDetail()
    {
        string id = Request.QueryString["id"];
        TblNoiDungTrangHome noiDungHome = noidungHomeDAO.GetNoiDung_ByID(Global.ConvertToInt(id));
        noidung1.Value = noiDungHome.NoiDung_Cot1;
        noidung2.Value = noiDungHome.NoiDung_Cot2;
        noidung3.Value = noiDungHome.NoiDung_Cot3;
        noidungbotoom.Value = noiDungHome.Noidung;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        TblNoiDungTrangHome noiDungHome = new TblNoiDungTrangHome();
        noiDungHome.NoiDung_Cot1 = Server.HtmlDecode(noidung1.Value);
        noiDungHome.NoiDung_Cot2 = Server.HtmlDecode(noidung2.Value);
        noiDungHome.NoiDung_Cot3 = Server.HtmlDecode(noidung3.Value);
        noiDungHome.Noidung = Server.HtmlDecode(noidungbotoom.Value);

        if (id == null || id == "")
        {
            noidungHomeDAO.Insert(noiDungHome, 1);
        }
        else
        {
            noiDungHome.Id = Global.ConvertToInt(id);
            noidungHomeDAO.Insert(noiDungHome, 2);
        }
    }
}
